package com.winit.tag.manager;

import com.datastax.driver.core.querybuilder.QueryBuilder;
import com.datastax.driver.core.querybuilder.Select;
import com.winit.tag.model.ConfigTag;
import com.winit.tag.repository.ConfigTagRepository;
import com.winit.tag.repository.TagOperations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjian on 2017/9/28.
 */
@Component
public class TagManager {

    private static Logger logger = LoggerFactory.getLogger(TagManager.class);

    @Autowired
    ConfigTagRepository repository;

    @Autowired
    private TagOperations tagOperations;

    public List<ConfigTag> getTag(String groupCode, String code) {
        return tagOperations.getTag(groupCode, code);
    }

    public  List<String> getTagCodesForGroup(String tag_group_code){
        List<ConfigTag> configTags = this.tagOperations.getTag(tag_group_code, null);
        List<String> configCodes = new ArrayList<String>();
        if (!CollectionUtils.isEmpty(configTags)){
            for (ConfigTag configTag : configTags){
                configCodes.add(configTag.getTag_code());
            }
        }
        return configCodes;
    }
}
